package wili.logic;

import java.util.Collections;
import java.util.Map;

import wili.c.Ca;
import wili.c.Str9a;
import wili.c.Str9a.IndMap;

/**
 *
 */
public class AndOrExp {
	public final String expSt;
	final String andOp = "&&", orOp = "||";
	public AndOrNode rootNode;
	public final boolean useSexp;

	public String toString() {
		return rootNode.toString();
	}

	@SuppressWarnings("rawtypes")
	public Boolean isTrue(Map cont) {
		return rootNode.isTrue(cont);
	}

	public static class EquivalentRet {
		public Map<String, Object> map;
		public String msg = "";

		public String toString() {
			if (map == null) {
				return "等价性未知.";
			} else if (map.isEmpty()) {
				String ret = "两式等价.";
				if (!msg.isEmpty())
					ret = ret + "\n" + msg;
				return ret;
			} else {
				String ret = "两式不等价.";
				if (!msg.isEmpty())
					ret = ret + "\n" + msg;
				return ret;
			}
		}

		@SuppressWarnings("unchecked")
		public EquivalentRet() {
			map = Collections.EMPTY_MAP;
		}

		public EquivalentRet(Map<String, Object> map, String msg) {
			this.map = map;
			this.msg = msg;
		}
	}

	public void setRootNode(AndOrNode root) {
		this.rootNode = root;
	}

	/**
	 *
	 */
	public static EquivalentRet isEquivalentLogicExp(String exp1, String exp2) {
		Ca.asert(false, "see AndOrExp2.java");
		return null;
	}

	IndMap lrIndMap;

	private AndOrExp(int useSexp, String expSt) {
		// expSt = "!" + expSt;
		this.useSexp = useSexp == 1;
		//expSt = Coms21.standarlizeExpOp(expSt);
		this.expSt = expSt;
		this.lrIndMap = Str9a.readBracketIndMap(expSt);
		this.rootNode = new AndOrNode(expSt, 0, expSt.length(), this);
	}

	public static AndOrExp newInst(int useSexp, String expSt) {
		if ("asdf".isEmpty()) {
			ToIndentLogicExp obj = new ToIndentLogicExp(expSt);
			return null;// new AndOrExp(obj.root);
		}
		AndOrExp ret = new AndOrExp(useSexp, expSt);
		return ret;
	}

	public void sortSonsBySt() {
		if (rootNode == null)
			return;
		rootNode.sortSonsBySt(9);
	}

	public void print(int use) {
		if (use < 0)
			return;
		rootNode.print("");
	}
}
